import {INCREMENT, DECREMENT, DECREMENTCOUNT, XGXX1, ADDCOUNTER, ADDTOCART , ADDUSER, ADDUSERINFO, CLEARUSERINFO} from './mutaions-types'
export default {
  // 方法 默认参数 state  getter ：Store的getter 属性
  [INCREMENT](state) {
    state.counter ++
  },
  [DECREMENT](state, getters) {
    state.counter --
  },
  [DECREMENTCOUNT](state, payload) {
    // 普通提交风格
    // state.counter += payload
    // 特殊提交风格  payload ==> 传入的对象
    console.log(payload)
    state.counter += payload.count
  },
  [XGXX1](state) {
    // 不是响应式 
    // state.info['address'] = 'hyx'
    // delete state.info.age 

    // 响应式 
    state.info.name = 'codecj'
    // Vue.set(obj/ary, key/index, 内容)
    // Vue.delete(obj/ary, key/index)
    // Vue.set(state.info, 'address', 'hyx')
    // Vue.delete(state.info, 'age')

  },
  // 商品数量加一
  [ADDCOUNTER](state, payload) {
    payload.count ++
  },
  // 添加新商品
  [ADDTOCART](state, payload) {
    state.cartList.push(payload)
  },
  // 添加用户账号
  [ADDUSER](state, payload) {
    state.users.push(payload)
  },
  // 添加用户信息
  [ADDUSERINFO](state, payload) {
    state.userItem = payload
    console.log('修改成功')
    console.log(state.userItem)
  },
  [CLEARUSERINFO](state, payload) {
    state.userItem = {
      img: '',
      userName: '',
      phone: ''
    }
  }

}